<!--页面主要内容-->
<main class="lyear-layout-content">

    <div class="container-fluid p-t-15">

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-toolbar d-flex flex-column flex-md-row">
                        <div class="toolbar-btn-action">
                            <!-- <a class="btn btn-primary m-r-5" href="#!"><i class="mdi mdi-plus"></i> 新增</a> -->
                            <a class="btn btn-success m-r-5 adopts" target-form="ids"><i class="mdi mdi-check"></i> 通过</a>
                            <a class="btn btn-warning m-r-5 fails"><i class="mdi mdi-block-helper"></i> 不通过</a>
                            
                            <a class="btn btn-danger dels"><i class="mdi mdi-window-close"></i> 批量删除</a>
                        </div>

                        <form class="search-bar ml-md-auto" method="get" role="form">
                            <input type="hidden" name="search_field" id="search-field" value="nickname" />
                            <div class="input-group ml-md-auto">
                                <div class="input-group-prepend">
                                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"
                                        aria-haspopup="true" aria-expanded="false" id="search-btn">{$SearchField == 'nickname' ? '昵称' : '管理员'}</button>
                                    <div class="dropdown-menu" style="">
                                        <a class="dropdown-item" data-field="nickname">用户名</a>
                                        <a class="dropdown-item" data-field="adminnickname">管理员</a>
                                    </div>
                                </div>
                                <input type="text" class="form-control" name="keyword" placeholder="{$keyword}">
                            </div>
                        </form>
                    </div>
                    <div class="card-body">

                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="check-all">
                                                <label class="custom-control-label" for="check-all"></label>
                                            </div>
                                        </th>
                                        <th>编号</th>
                                        <th>充值用户</th>
                                        <th>充值积分</th>
                                        <th>充值备注内容</th>
                                        <th>状态</th>
                                        <th>审核管理员</th>
                                        <th>充值时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {foreach $PayList as $item}
                                    <tr>
                                        <td>
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input ids" name="ids[]"
                                                    value="{$item.id}" id="ids-{$item.id}">
                                                <label class="custom-control-label" for="ids-{$item.id}"></label>
                                            </div>
                                        </td>
                                        <td>{++$num}</td>
                                        <td>{$item.user.nickname}</td>
                                        <td>{$item.point}</td>
                                        <td>{$item.content}</td>
                                        <td>
                                            {if $item.status == 0}
                                            <font class="text-info">{$item.status_text}</font>
                                            {elseif $item.status == 1}
                                            <font class="text-success">{$item.status_text}</font>
                                            {else /}
                                            <font class="text-danger">{$item.status_text}</font>
                                            {/if}
                                        </td>
                                        <td>{$item.admin.nickname ? $item.admin.nickname : ''}</td>
                                        <td>{$item.createtime|date="Y-m-d"}</td>
                                        <td>
                                            <div class="btn-group">
                                                {if $item.status == 0}
                                                <a class="btn btn-xs btn-default btn-success adopt" data-id="{$item.id}" data-toggle="tooltip"
                                                    data-original-title="审核通过"><i class="mdi mdi-file-eye"></i></a>
                                                <a class="btn btn-xs btn-default btn-danger fail" data-id="{$item.id}" data-toggle="tooltip"
                                                    data-original-title="审核不通过"><i class="mdi mdi-file-eye"></i></a>
                                                {else /}
                                                <a class="btn btn-xs btn-default del" data-id="{$item.id}"
                                                    data-toggle="tooltip" data-original-title="删除"><i
                                                        class="mdi mdi-window-close"></i></a>
                                                {/if}
                                            </div>
                                        </td>
                                    </tr>
                                    {/foreach}
                                </tbody>
                            </table>
                        </div>
                        {$PayList|raw}

                    </div>
                </div>
            </div>

        </div>

    </div>

</main>
<!--End 页面主要内容-->
<script>
    $(function () {
        $('.del').click(function () {
            $.confirm({
                title: '删除',
                content: '确认删除？删除后无法恢复',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let payid = $(this).data('id')

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/pay/del')}`,
                                data: {
                                    payid
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })


                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })

        $('.dels').click(function () {
            $.confirm({
                title: '批量删除',
                content: '确认批量删除？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let payid = GetId()

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/pay/del')}`,
                                data: {
                                    payid
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload()
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })


                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })

        })

        $('.adopt').click(function () {
            $.confirm({
                title: '审核',
                content: '确认审核通过？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let payid = $(this).data('id')

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/pay/status')}`,
                                data: {
                                    payid,
                                    action:'adopt'
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })

        $('.adopts').click(function () {
            $.confirm({
                title: '批量审核',
                content: '确认审核通过？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let payid = GetId()

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/pay/status')}`,
                                data: {
                                    payid,
                                    action:'adopt'
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })

        $('.fail').click(function () {
            $.confirm({
                title: '审核',
                content: '确认审核不通过？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let payid = $(this).data('id')

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/pay/status')}`,
                                data: {
                                    payid,
                                    action:'fail'
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })

        $('.fails').click(function () {
            $.confirm({
                title: '批量审核',
                content: '确认审核不通过？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let payid = GetId()

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/pay/status')}`,
                                data: {
                                    payid,
                                    action:'fail'
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })
    })
</script>